/** 
 * Copyright (C), 2010-2012, TIETIAO Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:BeanFactory.java
 * Version:1.0
 * Date:2011-11-19
 * Description: 
 * author:zhijian.zhang
 */
package com.tietiao.common.util;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.tietiao.dao.CommodityInfoMapper;
import com.tietiao.dao.model.CommodityInfo;

public class BeanFactory {

	/**
	 * 获取Spring上下文配置内容
	 */
	private static final ApplicationContext context = new ClassPathXmlApplicationContext(
			"spring/applicationContext.xml");

	/**
	 * 获取Bean
	 * 
	 * @param beanId
	 *            对应的Spring bean ID
	 * @return
	 */
	public static Object getBean(String beanId) {
		return context.getBean(beanId);
	}

	public static void init() {
		CommodityInfoMapper commodityInfoMapper = (CommodityInfoMapper) getBean("commodityInfoMapper");
		/*
		 * for (int i =2; i < 100; i++) { CommodityInfo commodityInfo = new
		 * CommodityInfo(); commodityInfo.setCommodityId(i);
		 * commodityInfo.setTitle("测试商品"+i); commodityInfo.setPicPath("lujis+" +
		 * i); commodityInfoMapper.insert(commodityInfo); }
		 * 
		 * UserCommentMapper userCommentMapper = (UserCommentMapper)
		 * getBean("userCommentMapper");
		 * 
		 * for(int i = 2; i < 100 ; i++) { UserComment userComment = new
		 * UserComment(); userComment.setCommentContent("wo de pinglun " + i);
		 * 
		 * userComment.setCommentId(i); if(i >= 2 && i < 10) {
		 * userComment.setCommodityId(3); } else if(i >=10 && i < 30) {
		 * userComment.setCommodityId(5); } else if(i >= 30 && i < 60) {
		 * userComment.setCommodityId(10); } else {
		 * userComment.setCommodityId(i); }
		 * userCommentMapper.insert(userComment); }
		 * 
		 * TietiaoMapper tietiaoMapper = (TietiaoMapper)
		 * getBean("tietiaoMapper");
		 * 
		 * for(int i = 2; i < 100 ; i++) { Tietiao tietiao = new Tietiao();
		 * tietiao.setFavoriteId(1); tietiao.setCommodityId(i);
		 * tietiao.setUserId(1); tietiaoMapper.insert(tietiao); }
		 * 
		 * 
		 * UserRecomCommodityMapper userRecomCommodityMapper =
		 * (UserRecomCommodityMapper) getBean("userRecomCommodityMapper");
		 * 
		 * for(int i = 2; i < 100 ; i++) { UserRecomCommodity userRecomCommodity
		 * = new UserRecomCommodity(); userRecomCommodity.setCommodityId(i);
		 * userRecomCommodity.setRecomUserId(1);
		 * userRecomCommodityMapper.insert(userRecomCommodity); }
		 * 
		 * 
		 * MidLableCommodityMapper midLableCommodityMapper =
		 * (MidLableCommodityMapper) getBean("midLableCommodityMapper"); for(int
		 * i = 2; i < 100 ; i++) { MidLableCommodity midLableCommodity = new
		 * MidLableCommodity(); midLableCommodity.setCommodityId(i);
		 * midLableCommodity.setLabelId(9);
		 * midLableCommodityMapper.insert(midLableCommodity); }
		 */
	}

	public static void main(String[] args) {
		CommodityInfoMapper commodityInfoMapper = (CommodityInfoMapper) getBean("commodityInfoMapper");
		List<CommodityInfo> commodityInfos = commodityInfoMapper
				.selectByExample(null);

		String delIds = "";

		for (int i = 0; i < commodityInfos.size(); i++) {
			delIds +=  commodityInfos.get(i).getCommodityId();
			if(i < commodityInfos.size() - 1) {
				delIds+=",";
			}
		}
		commodityInfoMapper.delCommoditys(delIds);

	}
}
